using IQIGame.Onigao.Game;
using UnityEngine.Assertions;

namespace IQIGame.Onigao.GamePlay
{
    public class MainCityMoveComponent : EntityMoveComponent
    {
        private EntityAnimationComponent _animComponent;

        public MainCityRealityEntity entity => _entity as MainCityRealityEntity;
        public override TransformAgent transform => entity.transform;
        protected override TNavigationController navigationCtrl => MainCityModule.Instance.mainController.regionCtrl.navigationCtrl;
        protected override EntityAnimationComponent animComponent
        {
            get
            {
                _animComponent = _animComponent ?? this.entity.GetComponent<MainCityAnimationComponent>(ETComponentType.EntityAnimation);
                return _animComponent;
            }
        }

        public override void OnComponentEvent<T>(TComponentEvent eventType, T arg)
        {
            switch (eventType)
            {
                case TComponentEvent.OnEntityObjectLoaded:
                    if (arg is EntityLoadState loadState && (loadState == EntityLoadState.None || loadState == EntityLoadState.Error))
                    {
                        return;
                    }
                    Assert.IsNotNull(this.transform, "[MainCityMoveComponent|OnCreate] Transform is null");
                    if (this.isPlayerAvatarEntity)
                    {
                        AddCharacterController();
                        return;
                    }
                    break;
                case TComponentEvent.OnEntityObjectHided:
                    OnHide();
                    break;
            }
        }

        public override uint MaxStore => 50;

        public override void OnPoolReset()
        {
            _animComponent = null;
        }
    }
}
